import os.path
import re

Hall_Port = '6320'
FireRuleName = 'auto_firewall_'
FireWallVersion = 0
AutoFlushTime = 3600.0
pattern_ipv4 = re.compile(r"^\d+\.\d+\.\d+\.\d+:\d+$")
pattern_ipv6 = re.compile(r'^(\[[0-9a-fA-F:]+)]:(\d+)$')
SqlConfig = 'mysql+pymysql://root@localhost:3306/userlogin?charset=utf8'

def load():
    global Hall_Port, FireRuleName, FireWallVersion, AutoFlushTime, SqlConfig
    if not os.path.exists('config.conf'):
        with open('config.conf', 'w') as f:
            f.write('# 防火墙配置文件\n')
            f.write('# Hall_Port:大厅端口\n')
            f.write('# FireRuleName:防火墙规则名称\n')
            f.write('# FireWallVersion:防火墙版本号\n')
            f.write('Hall_Port=6320\n')
            f.write('FireRuleName=auto_firewall_\n')
            f.write('FireWallVersion=1\n')
            f.write('AutoFlushTime=3600\n')
            f.write('SqlConnect=mysql+pymysql://root@localhost:3306/userlogin?charset=utf8\n')
            f.close()
    with open('config.conf', 'r') as f:
        lines = f.readlines()
        for line in lines:
            if line.startswith('#'):
                continue
            if line.startswith('Hall_Port'):
                Hall_Port = line.split('=')[1].strip()
            if line.startswith('FireRuleName'):
                FireRuleName = line.split('=')[1].strip()
            if line.startswith('FireWallVersion'):
                FireWallVersion = line.split('=')[1].strip()
            if line.startswith('AutoFlushTime'):
                AutoFlushTime = float(line.split('=')[1].strip())
            if line.startswith('SqlConnect'):
                SqlConfig = line.split('=')[1].strip()
        f.close()


load()